const Service = require('egg').Service;

class IfmtionService extends Service {
	async getIfmtion() {
		const {
			app,
			ctx
		} = this;
		const {
			keyword
		} = ctx.query;
		let sql = `select * from ifmtion where 1=1 `
		if (keyword) {
			sql += `and title like "%${keyword}%" `
		}
		const data = await app.mysql.query(sql)
		return data
	}
	async addIfmtion() {
		const {
			ctx,
			app
		} = this;
		const data = await app.mysql.insert('ifmtion', {
			...ctx.request.body,
			create_time: Date.now()
		})
		return data;
	}
	async delIfmtion() {
		const {
			ctx,
			app
		} = this;
		const data = await app.mysql.delete('ifmtion', {
			id: ctx.params.id
		}); // 根据id删除
		return data
	}
	async editIfmtion() {
		const {
			ctx,
			app
		} = this;
		const data = await app.mysql.update('ifmtion', {
			...ctx.request.body,
		})
		return data;
	}
	async editType() {
		const { ctx, app } = this
		const data = await app.mysql.update('ifmtion', {
			...ctx.request.body,
		})
		return data;
	}
}

module.exports = IfmtionService;
